package com.wayne.mapper;

import com.wayne.pojo.User;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.redis.RedisCache;

import java.util.List;
//开启二级缓存
@CacheNamespace(implementation = RedisCache.class)
public interface IUserMapper {

  /**
   * 查询全部
   *
   * @return
   */
  List<User> findAll();

  /**
   * 根据条件查询
   *
   * @param user
   * @return
   */
  List<User> findByCondition(User user);

  /**
   * 更新用户信息
   * @param user
   */
  @Update("update t_user set username=#{username} where id = #{id}")
  void updateUser(User user);
  /**
   * 根据id集合查询
   *
   * @param ids
   * @return
   */
  List<User> findByIds(@Param("ids") List<Integer> ids);

  List<User> findUserAndOrder();

  List<User> findUserAndRole();

  // useCache 是否使用二级缓存 默认true
  @Options(useCache = true)
  @Select("select * from t_user where id = #{id}")
  User findById(Integer id);

  @Results({
      @Result(property = "id",column = "id"),
      @Result(property = "username",column = "username"),
      @Result(property = "orderList",column = "id", javaType = List.class,
      many = @Many(select = "com.wayne.mapper.IOrderMapper.findByUid"))
  })
  @Select("select * from t_user")
  List<User> selectUserAndOrder();
}
